#ifndef BACKEND_SYLIXOSINPUT_H
#define BACKEND_SYLIXOSINPUT_H

#include <mouse.h>
#include <keyboard.h>
#include <wayland-server-core.h>
#include <wlr/backend/interface.h>
#include <wlr/backend/sylixosinput.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_switch.h>
#include <wlr/types/wlr_tablet_pad.h>
#include <wlr/types/wlr_tablet_tool.h>
#include <wlr/types/wlr_touch.h>

struct wlr_sylixosinput_input_device;

struct wlr_sylixosinput_backend {
	struct wlr_backend backend;

	struct wl_display *display;

	struct wlr_sylixosinput_input_device *device;

	int xmse_fd;
	int xkbd_fd;
	struct wl_event_source *xmse_event;
	struct wl_event_source *xkbd_event;

	struct wl_listener display_destroy;
	struct wl_listener session_destroy;
	struct wl_listener session_signal;

	struct wl_list devices; // wlr_libinput_device::link
};

struct wlr_sylixosinput_input_device {
	struct wlr_keyboard keyboard;
	struct wlr_pointer pointer;
	struct wlr_switch switch_device;
	struct wlr_touch touch;
	struct wlr_tablet tablet;
	struct wl_list tablet_tools; // see backend/libinput/tablet_tool.c
	struct wlr_tablet_pad tablet_pad;

	struct wl_list link;
};

uint32_t usec_to_msec(uint64_t usec);

void handle_xmse_event(struct wlr_sylixosinput_backend *state, int fd);
void handle_xkbd_event(struct wlr_sylixosinput_backend *state, int fd);
void destroy_sylixosinput_input_device(struct wlr_sylixosinput_input_device *dev);
void handle_device_added(struct wlr_sylixosinput_backend *backend);

extern const struct wlr_pointer_impl sylixosinput_pointer_impl;

void init_device_pointer(struct wlr_sylixosinput_input_device *dev);
struct wlr_sylixosinput_input_device *device_from_pointer(struct wlr_pointer *kb);
void handle_pointer_motion(mouse_event_notify *event, struct wlr_pointer *pointer);
void handle_pointer_motion_abs(mouse_event_notify *event, struct wlr_pointer *pointer);
void handle_pointer_button(mouse_event_notify *event, struct wlr_pointer *pointer);
void handle_pointer_axis(mouse_event_notify *event, struct wlr_pointer *pointer);

extern const struct wlr_keyboard_impl sylixosinput_keyboard_impl;

void init_device_keyboard(struct wlr_sylixosinput_input_device *dev);
struct wlr_sylixosinput_input_device *device_from_keyboard(struct wlr_keyboard *kb);
void handle_keyboard_key(keyboard_event_notify *event, struct wlr_keyboard *kb);
#endif
